package com.wyq.new_springboot.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyq.new_springboot.entity.TBlog;
import com.wyq.new_springboot.mapper.TBlogMapper;
import com.wyq.new_springboot.service.ITBlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr Wei
 * @since 2021-03-25
 */
@Service
public class TBlogServiceImpl extends ServiceImpl<TBlogMapper, TBlog> implements ITBlogService {
    @Autowired
    TBlogMapper tBlogMapper;
    /**
     * 发布文章
     * @param tBlog
     */
    @Override
    public void insertBlog(TBlog tBlog) {
        tBlogMapper.insert(tBlog);
    }

    /**
     * 查询所有的博客
     * @return
     */
    @Override
    public List<TBlog> getAllBlog() {
        QueryWrapper<TBlog> queryWrapper=new QueryWrapper<>();
        queryWrapper.notIn("id",-1);
        return tBlogMapper.selectList(queryWrapper);
    }

    /**
     * 获取分页查询数据
     * @return
     */
    @Override
    public List<TBlog> getPages(long current,long size) {
        Page<TBlog> page=new Page<>(current,size);
        QueryWrapper<TBlog> queryWrapper=new QueryWrapper<>();
        queryWrapper.notIn("id",-1);
        IPage<TBlog> tBlogIPage = tBlogMapper.selectPage(page, queryWrapper);
        return tBlogIPage.getRecords();
    }
}
